home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / EXTERNALMETHOD.PY < prev    next >
Encoding:
Text File  |  2000-07-03  |  6.8 KB  |  172 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64.  
  65.  
  66.  
  67. def manage_addExternalMethod(self, id, title, module, function):
  68.     """
  69.  
  70.     Add an external method to an ObjectManager.
  71.   
  72.     In addition to the standard object-creation arguments,
  73.     'id' and title, the following arguments are defined:
  74.  
  75.         function -- The name of the python function. This can be a
  76.           an ordinary Python function, or a bound method.
  77.  
  78.         module -- The name of the file containing the function
  79.           definition.
  80.  
  81.         The module normally resides in the 'Extensions'
  82.         directory, however, the file name may have a prefix of
  83.         'product.', indicating that it should be found in a product
  84.         directory.
  85.  
  86.         For example, if the module is: 'ACMEWidgets.foo', then an
  87.         attempt will first be made to use the file
  88.         'lib/python/Products/ACMEWidgets/Extensions/foo.py'. If this
  89.         failes, then the file 'Extensions/ACMEWidgets.foo.py' will be
  90.         used.
  91.  
  92.     """
  93.  
  94. class ExternalMethod:
  95.     """
  96.  
  97.     Web-callable functions that encapsulate external python functions.
  98.  
  99.     The function is defined in an external file.  This file is treated
  100.     like a module, but is not a module.  It is not imported directly,
  101.     but is rather read and evaluated.  The file must reside in the
  102.     'Extensions' subdirectory of the Zope installation, or in an
  103.     'Extensions' subdirectory of a product directory.
  104.  
  105.     Due to the way ExternalMethods are loaded, it is not *currently*
  106.     possible to use Python modules that reside in the 'Extensions'
  107.     directory.  It is possible to load modules found in the
  108.     'lib/python' directory of the Zope installation, or in
  109.     packages that are in the 'lib/python' directory.
  110.  
  111.     """
  112.  
  113.     __constructor__=manage_addExternalMethod
  114.  
  115.     def manage_edit(self, title, module, function, REQUEST=None):
  116.         """
  117.         Change the external method
  118.  
  119.         See the description of manage_addExternalMethod for a
  120.         description of the arguments 'module' and 'function'.
  121.  
  122.         Note that calling 'manage_edit' causes the "module" to be
  123.         effectively reloaded.  This is useful during debugging to see
  124.         the effects of changes, but can lead to problems of functions
  125.         rely on shared global data.
  126.  
  127.         """
  128.  
  129.     def __call__(self, *args, **kw):
  130.  
  131.         """
  132.  
  133.         Call an ExternalMethod
  134.  
  135.         Calling an External Method is roughly equivalent to calling
  136.         the original actual function from Python.  Positional and
  137.         keyword parameters can be passed as usual.  Note however that
  138.         unlike the case of a normal Python method, the "self" argument
  139.         must be passed explicitly.  An exception to this rule is made
  140.         if:
  141.  
  142.         - The supplied number of arguments is one less than the
  143.           required number of arguments, and
  144.  
  145.         - The name of the function\'s first argument is 'self'.
  146.  
  147.         In this case, the URL parent of the object is supplied as the
  148.         first argument.
  149.  
  150.         """
  151.